﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business;
using ZLCMS.Data.Model;
using NHibernate;
using ZLCMS.Business.DwzFrame;
using NHibernate.Criterion;

namespace ZLCMS.Web.SystemManage.Basics.Param
{
    public partial class Delete : System.Web.UI.Page
    {
        FrameHelper _framePage;
        protected void Page_Load(object sender, EventArgs e)
        {
            string ids;
            
            _framePage= new FrameHelper(this);
            SysParam systemParamDB;

            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                if (Request["ajax"] == "dels" & !String.IsNullOrEmpty(Request["iid"]))
                {
                    ids = Request["ids"];
                    if (!String.IsNullOrEmpty(ids))
                    {
                        String[] idArray = ids.Split(',');
                        foreach (String id in idArray)
                        {
                            try
                            {
                                systemParamDB = session.CreateCriteria<SysParam>().Add(Expression.Eq("GroupCode", Request["iid"])).Add(Expression.Eq("ItemCode", id)).UniqueResult<SysParam>();
                                session.Delete(systemParamDB);
                            }
                            catch (System.Exception ex)
                            {
                                _framePage.Alert(new ReturnCode() { statusCode = 300, message = "操作失败-" + ex.InnerException.Message });
                                return;
                            }
                        }
                        session.Flush();
                    }
                }
                else if (!String.IsNullOrEmpty(Request["iid"]) && !String.IsNullOrEmpty(Request["vid"]))
                {
                    try
                    {
                        systemParamDB = session.CreateCriteria<SysParam>().Add(Expression.Eq("GroupCode", Request["iid"])).Add(Expression.Eq("ItemCode", Request["vid"])).UniqueResult<SysParam>();
                        session.Delete(systemParamDB);

                        session.Flush();
                    }
                    catch (System.Exception ex)
                    {
                        _framePage.Alert(new ReturnCode() { statusCode = 300, message = "操作失败-" + ex.InnerException.Message });
                        return;
                    }
                }
            }
            _framePage.Alert(new ReturnCode() { statusCode = 200, message = "操作成功!" });

        }
    }
}
